﻿using System;

namespace TextEditor
{
    

    public class A_FieldName : A_Action
    {
        public override string ActionName()
        {
            return "fieldname";
        }

        public override bool Execute()
        {
            ZYTextElement currentElement = base.myOwnerDocument.Content.CurrentElement;
            if ((currentElement is ZYTextSelect) || (currentElement is ZYTextInput))
            {
                currentElement.Attributes.SetValue("id", base.Param1);
                if (currentElement is ZYTextInput)
                {
                    currentElement.Attributes.SetValue("id", base.Param1);
                    currentElement.RefreshSize();
                    base.myOwnerDocument.RefreshLine();
                    base.myOwnerDocument.UpdateViewNoScroll();
                }
            }
            else
            {
                currentElement.Parent.Attributes.SetValue("id", base.Param1);
                if (currentElement.Parent is ZYTextDiv)
                {
                    currentElement.Parent.Attributes.SetValue("id", base.Param1);
                }
            }
            return true;
        }
               
        public override string GetText()
        {
            ZYTextElement currentElement = base.myOwnerDocument.Content.CurrentElement;
            if ((currentElement is ZYTextSelect) || (currentElement is ZYTextInput))
            {
                return currentElement.Attributes.GetString("id");
            }
            return currentElement.Parent.Attributes.GetString("id");
        }

        public override bool isEnable()
        {
            return (base.myOwnerDocument.CanModify() && base.isEnable());
        }
    }
}

